#!/usr/bin/env python
# Python Network Programming Cookbook -- Chapter -1
# THis program is optinmized for python 2.7. It may run on any
# other Python version with/without modifications.

import socket
from binascii import hexlify

def convert_ipv4_address():
    for ip_addr in ['127.0.0.1', '192.168.0.1']:
        packed_ip_addr = socket.inet_aton(ip_addr)
        unpacked_ip_addr = socket.inet_ntoa(packed_ip_addr)
        print "IP address: %s => Packed: %s, Unpacked: %s" \
            %(ip_addr, hexlify(packed_ip_addr), unpacked_ip_addr)


if __name__ == "__main__":
    convert_ipv4_address()
